package class91To100;

import java.io.*;

// 矩阵快速幂
// 测试链接：https://www.luogu.com.cn/problem/P3390
public class MatrixQuickPow {
    public static int MOD = 1000000007;
    public static int n;
    public static long k;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(System.out);
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            long[][] arr = new long[n][n];
            in.nextToken();
            k = (long) in.nval;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    in.nextToken();
                    arr[i][j] = (int) in.nval;
                }
            }
            long[][] ans = solve(arr);
            for (int i = 0; i < ans.length; i++) {
                for (int j = 0; j < ans[0].length; j++) {
                    out.print(ans[i][j] + " ");
                }
                out.println();
            }
        }
        out.flush();
        out.close();
        br.close();
    }

    public static long[][] solve(long[][] arr) {
        return power(arr, k);
    }

    // a的列数一定要等于b的行数
    public static long[][] multiply(long[][] a, long[][] b) {
        int n = a.length;
        int m = b[0].length;
        int t = a[0].length;
        long[][] ans = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int c = 0; c < t; c++) {
                    ans[i][j] = (ans[i][j] + (a[i][c] * b[c][j]) % MOD) % MOD;
                }
            }
        }
        return ans;
    }

    // 矩阵快速幂
    public static long[][] power(long[][] m, long p) {
        int n = m.length;
        long[][] ans = new long[n][n];
        // 单位矩阵(左上到右下为1，其余全为0)
        for (int i = 0; i < n; i++) {
            ans[i][i] = 1;
        }
        for (; p != 0; p >>= 1) {
            if ((p & 1) != 0) {
                ans = multiply(ans, m);
            }
            m = multiply(m, m);
        }
        return ans;
    }
}
